#ifndef FOC_SMO_H
#define FOC_SMO_H

#include "Encoder.h"
#include "Foc_math.h"
#include "foc_filter.h"

typedef struct
{
    PLL_t pll;

    Encoder_t Encoder;

    V_alphabeta_t Real_U; /* αβ轴输U出的电压 */
    I_alphabeta_t Real_I; /* αβ轴采集到的电流 */

    I_alphabeta_t Est_I; /* αβ轴估算的电流 */
    I_alphabeta_t Est_U; /* αβ轴估算的反电动势 */

    I_alphabeta_t Est_I_err; /* 观测的电流的误差 */

    I_alphabeta_t Est_V; /* αβ轴 V平面*/
    float h;             /* 滑模系数*/
    float Rs;            /* 相电阻 */
    float Ls;            /* 相电感 */
    float Ts;            /* 周期时间：s*/
    float Rs_Ls;
    float _1_Ls;
    float atan_theta;

} FOC_SMO_t;

void FOC_SMO_Init(FOC_SMO_t* foc_smo, float Rs, float Ls, float Ts, uint32_t pole_pairs, float max_speed);
void FOC_SMO_Angle_Cale(FOC_SMO_t* foc_smo);

void FOC_SMO_Angle_Calc(FOC_SMO_t* foc_smo, I_alphabeta_t Real_I, V_alphabeta_t Real_U);
void FOC_SMO_Speed_Calc(FOC_SMO_t* foc_smo);
void FOC_SMO_Clear(FOC_SMO_t* foc_smo);

#endif
